using System;
using System.Windows.Forms;

namespace CastleSample.UI.Core
{
    public class MenuItemInfo
    {
        private ToolStripMenuItem m_MenuItem;

        public ToolStripMenuItem MenuItem
        {
            get { return m_MenuItem; }
        }

        public MenuItemInfo(string key, string caption)
        {
            m_MenuItem = new ToolStripMenuItem();
            Key = key;
            Caption = caption;
        }

        public MenuItemInfo(string key, string caption, EventHandler clickEventHandler)
        {
            m_MenuItem = new ToolStripMenuItem();
            Key = key;
            Caption = caption;
            Click += clickEventHandler;
        }

        public MenuItemInfo(ToolStripMenuItem menuItem)
        {
            m_MenuItem = menuItem;
        }

        private bool m_IsSeparator = false;

        public bool IsSeparator
        {
            get { return m_IsSeparator; }
            set { m_IsSeparator = value; }
        }

        public string Key
        {
            get { return m_MenuItem.Name.TrimStart("menuItem".ToCharArray()); }
            set { m_MenuItem.Name = "menuItem" + value; }
        }

        public string Caption
        {
            get { return m_MenuItem.Text; }
            set
            {
                IsSeparator = (string.IsNullOrEmpty(value) || (value.Trim() == "-"));

                m_MenuItem.Text = value;
            }
        }

        public bool Checked
        {
            get { return m_MenuItem.Checked; }
            set { m_MenuItem.Checked = value; }
        }

        public bool Enabled
        {
            get { return m_MenuItem.Enabled; }
            set { m_MenuItem.Enabled = value; }
        }

        public bool Visible
        {
            get { return m_MenuItem.Visible; }
            set { m_MenuItem.Visible = value; }
        }

        public Keys ShortcutKeys
        {
            get { return m_MenuItem.ShortcutKeys; }
            set { m_MenuItem.ShortcutKeys = value; }
        }

        public string ShortcutKeyDisplayString
        {
            get { return m_MenuItem.ShortcutKeyDisplayString; }
            set { m_MenuItem.ShortcutKeyDisplayString = value; }
        }

        public event EventHandler Click
        {
            add { m_MenuItem.Click += value; }
            remove { m_MenuItem.Click -= value; }
        }
    }
}